package com.zhongying.otherconfig;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zhongying.jf.dto.SystemPlatformDto;
import com.zhongying.jf.service.SystemPlatformService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;

import com.zhongying.sys.utils.PageUtils;
import com.zhongying.sys.utils.R;


/**
 * 平台
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-09-25 15:59:27
 */
@Controller
@RequestMapping("systemplatform")
public class SystemPlatformController {
	@Autowired
	private SystemPlatformService systemPlatformService;
	
	@RequestMapping("/systemplatform.html")
	public String list(){
		return "systemplatform/systemplatform.html";
	}
	
	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping("/list")
	@RequiresPermissions("systemplatform:list")
	public R list(Integer page, Integer limit){
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		
		//查询列表数据
		List<SystemPlatformDto> systemPlatformList = systemPlatformService.queryList(map);
		int total = systemPlatformService.queryTotal(map);
		
		PageUtils pageUtil = new PageUtils(systemPlatformList, total, limit, page);
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@ResponseBody
	@RequestMapping("/info/{id}")
	@RequiresPermissions("systemplatform:info")
	public R info(@PathVariable("id") Long id){
		SystemPlatformDto systemPlatform = systemPlatformService.queryObject(id);
		
		return R.ok().put("systemPlatform", systemPlatform);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@RequestMapping("/save")
	@RequiresPermissions("systemplatform:save")
	public R save(@RequestBody SystemPlatformDto systemPlatform){
		systemPlatform.setCreateTime(new Date());
		systemPlatform.setUpdateTime(null);
		systemPlatformService.save(systemPlatform);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("systemplatform:update")
	public R update(@RequestBody SystemPlatformDto systemPlatform){
		systemPlatformService.update(systemPlatform);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("systemplatform:delete")
	public R delete(@RequestBody Long[] ids){
		systemPlatformService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
